package com.thread.main.thread;

/**
 * @auther zhangwj
 * @date 2020/4/21 2:52 下午
 */
public class WaitDemo {

    public static void main(String[] args) throws InterruptedException {
        Integer sync = 1;
        ThreadC threadC = new ThreadC(sync);
        ThreadD threadD = new ThreadD(sync);
        threadC.start();
        Thread.sleep(5000);
        threadD.start();
    }

}

class ThreadC extends Thread {

    private Integer sync;

    ThreadC(Integer sync) {
        this.sync = sync;
    }

    @Override
    public void run() {
        super.run();
        try {
            out();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static synchronized void out() throws InterruptedException {
        System.out.println("我开始等待----");
        Thread.currentThread().wait();
        System.out.println("我又开始了");

    }
}

class ThreadD extends Thread {

    private Integer sync;

    ThreadD(Integer sync) {
        this.sync = sync;
    }

    @Override
    public void run() {
        super.run();
        try {
            this.out();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static synchronized void out() throws InterruptedException {
        System.out.println("我开始通知----");
        Thread.currentThread().wait();
        System.out.println("我通知结束----");
    }
}